css: Query icon theme from style, not from settings
authorBenjamin Otte <otte@redhat.com>
Wed, 2 Dec 2015 02:18:26 +0000 (03:18 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 2 Dec 2015 02:18:26 +0000 (03:18 +0100)
No need to look at the settings when the CSS has a property for the icon
theme.

gtk/deprecated/gtkiconfactory.c
gtk/deprecated/gtknumerableicon.c
gtk/gtkcssiconthemevalue.c
gtk/gtkcssiconthemevalueprivate.h
gtk/gtkcssimageicontheme.c
gtk/gtkfilechooserbutton.c
gtk/gtkfilesystem.c
gtk/gtkiconhelper.c
gtk/gtkmountoperation.c
gtk/gtkrecentchooserdefault.c
gtk/gtkwindow.c

index 97282a5c794e4470b9f2593fd3535ea849b515bd..d2ada241e16101c9c95d0bfd7ca815fdf1b51912 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include "gtkcssenumvalueprivate.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkiconfactory.h"
 #include "gtkiconcache.h"
 #include "gtkdebug.h"
@@ -1275,14 +1276,13 @@ render_icon_name_pixbuf (GtkIconSource    *icon_source,
   GdkPixbuf *pixbuf;
   GdkPixbuf *tmp_pixbuf;
   GtkIconSource tmp_source;
-  GdkScreen *screen;
   GtkIconTheme *icon_theme;
   gint width, height, pixel_size;
   gint *sizes, *s, dist;
   GError *error = NULL;
 
-  screen = gtk_style_context_get_screen (context);
-  icon_theme = gtk_icon_theme_get_for_screen (screen);
+  icon_theme = gtk_css_icon_theme_value_get_icon_theme
+    (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_THEME));
 
   if (!gtk_icon_size_lookup (size, &width, &height))
     {
index 832390cf3c11690d8aea791e29c2925c2fcda79c..7f63f4da310609895ba194c89c6ee40362eeefa9 100644 (file)
 #include "gtknumerableicon.h"
 #include "gtknumerableiconprivate.h"
 
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkicontheme.h"
 #include "gtkintl.h"
+#include "gtkstylepropertyprivate.h"
 #include "gtkwidget.h"
 #include "gtkwidgetpath.h"
 #include "gtkwindow.h"
@@ -192,15 +194,14 @@ static cairo_surface_t *
 draw_from_gicon (GtkNumerableIcon *self)
 {
   GtkIconTheme *theme;
-  GdkScreen *screen;
   GtkIconInfo *info;
   GdkPixbuf *pixbuf;
   cairo_surface_t *surface;
 
   if (self->priv->style != NULL)
     {
-      screen = gtk_style_context_get_screen (self->priv->style);
-      theme = gtk_icon_theme_get_for_screen (screen);
+      theme = gtk_css_icon_theme_value_get_icon_theme
+          (_gtk_style_context_peek_property (self->priv->style, GTK_CSS_PROPERTY_ICON_THEME));
     }
   else
     {
index 3956d88ca5d98b9403ed814ba249babee0665fe9..84eb02f90c3b83c23beb898ce37a7845b9866243 100644 (file)
@@ -131,3 +131,10 @@ _gtk_css_icon_theme_value_new (void)
   return _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ICON_THEME);
 }
 
+GtkIconTheme *
+gtk_css_icon_theme_value_get_icon_theme (GtkCssValue *value)
+{
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ICON_THEME, NULL);
+
+  return value->icontheme;
+}
index 6acfdc6f3f92b9cedc4c1fe3adc8997dbf50c93e..f11df884a4e8b4b437ebfeb0d3b579a56d12e001 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__
 #define __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__
 
+#include "gtkicontheme.h"
+
 #include "gtkcssparserprivate.h"
 #include "gtkcssvalueprivate.h"
 
@@ -27,6 +29,8 @@ G_BEGIN_DECLS
 
 GtkCssValue *   _gtk_css_icon_theme_value_new           (void);
 
+GtkIconTheme *  gtk_css_icon_theme_value_get_icon_theme (GtkCssValue    *value);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__ */
index 484b77a942b3ca50e000e9938d5ae6d126b587cd..73c8a628a114e0d00c7e5972202be70909c92bfd 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <math.h>
 
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
 #include "gtksettingsprivate.h"
 #include "gtkstyleproviderprivate.h"
@@ -133,18 +134,10 @@ gtk_css_image_icon_theme_compute (GtkCssImage             *image,
 {
   GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image);
   GtkCssImageIconTheme *copy;
-  GtkSettings *settings;
-  GdkScreen *screen;
-
-  settings = _gtk_style_provider_private_get_settings (provider);
-  if (settings == NULL)
-    screen = gdk_screen_get_default ();
-  else
-    screen = _gtk_settings_get_screen (settings);
 
   copy = g_object_new (GTK_TYPE_CSS_IMAGE_ICON_THEME, NULL);
   copy->name = g_strdup (icon_theme->name);
-  copy->icon_theme = gtk_icon_theme_get_for_screen (screen);
+  copy->icon_theme = gtk_css_icon_theme_value_get_icon_theme (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME));
   copy->scale = _gtk_style_provider_private_get_scale (provider);
   copy->color = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_COLOR));
 
index 000482ebf8974e40e76ff212d70866f1cd25c315..8ac5b9e36d7caea2f68313c3acc74c7358e13c01 100644 (file)
@@ -34,6 +34,7 @@
 #include "gtkcellrenderertext.h"
 #include "gtkcellrendererpixbuf.h"
 #include "gtkcombobox.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkdnd.h"
 #include "gtkicontheme.h"
 #include "deprecated/gtkiconfactory.h"
@@ -1489,10 +1490,8 @@ gtk_file_chooser_button_screen_changed (GtkWidget *widget,
 static GtkIconTheme *
 get_icon_theme (GtkWidget *widget)
 {
-  if (gtk_widget_has_screen (widget))
-    return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
-
-  return gtk_icon_theme_get_default ();
+  return gtk_css_icon_theme_value_get_icon_theme
+    (_gtk_style_context_peek_property (gtk_widget_get_style_context (widget), GTK_CSS_PROPERTY_ICON_THEME));
 }
 
 
@@ -1963,7 +1962,7 @@ model_add_bookmarks (GtkFileChooserButton *button,
          if (!label)
            label = _gtk_file_chooser_label_for_file (file);
 
-         icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
+          icon_theme = get_icon_theme (GTK_WIDGET (button));
          surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote",
                                                 button->priv->icon_size, 
                                                 gtk_widget_get_scale_factor (GTK_WIDGET (button)),
@@ -2070,7 +2069,7 @@ model_update_current_folder (GtkFileChooserButton *button,
       if (!label)
        label = _gtk_file_chooser_label_for_file (file);
 
-      icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
+      icon_theme = get_icon_theme (GTK_WIDGET (button));
 
       if (g_file_is_native (file))
          surface = gtk_icon_theme_load_surface (icon_theme, "folder",
index a26619443b1b3aa8027e14052030ff857ea48ad9..a69ba905f484f932c6a116187e95b4f3e118cc5b 100644 (file)
 
 #include "config.h"
 
-#include <string.h>
+#include "gtkfilesystem.h"
 
+#include <string.h>
 #include <glib/gi18n-lib.h>
 
 #include "gtkfilechooser.h"
-#include "gtkfilesystem.h"
-#include "gtkicontheme.h"
-#include "gtkprivate.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkintl.h"
+#include "gtkprivate.h"
+#include "gtkstylecontextprivate.h"
 
 /* #define DEBUG_MODE */
 #ifdef DEBUG_MODE
@@ -707,14 +708,15 @@ get_surface_from_gicon (GIcon      *icon,
                        gint        icon_size,
                        GError    **error)
 {
-  GdkScreen *screen;
+  GtkStyleContext *context;
   GtkIconTheme *icon_theme;
   GtkIconInfo *icon_info;
   GdkPixbuf *pixbuf;
   cairo_surface_t *surface;
 
-  screen = gtk_widget_get_screen (GTK_WIDGET (widget));
-  icon_theme = gtk_icon_theme_get_for_screen (screen);
+  context = gtk_widget_get_style_context (widget);
+  icon_theme = gtk_css_icon_theme_value_get_icon_theme
+    (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_THEME));
 
   icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme,
                                                         icon,
@@ -726,7 +728,7 @@ get_surface_from_gicon (GIcon      *icon,
     return NULL;
 
   pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
-                                                    gtk_widget_get_style_context (widget),
+                                                    context,
                                                     NULL,
                                                     error);
 
index 25fec55db87af7339ce383bc75c4185415f2927c..61bcc21178b82d890a0cc3c8ec5d628d74e2473b 100644 (file)
@@ -24,6 +24,7 @@
 #include <math.h>
 
 #include "gtkcssenumvalueprivate.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkrender.h"
 #include "gtkstylecontextprivate.h"
 #include "deprecated/gtkstock.h"
@@ -457,7 +458,8 @@ ensure_surface_for_gicon (GtkIconHelper   *self,
   GtkIconLookupFlags flags;
   cairo_surface_t *surface;
 
-  icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context));
+  icon_theme = gtk_css_icon_theme_value_get_icon_theme
+    (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_THEME));
   flags = get_icon_lookup_flags (self, context);
 
   ensure_icon_size (self, &width, &height);
index 4d7a87b0a4109d9fa631ba1857676d75eec77141..f95834d4d1898af53b592e9a349992a89da39086 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "gtkmountoperationprivate.h"
 #include "gtkbox.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkdbusgenerated.h"
 #include "gtkentry.h"
 #include "gtkbox.h"
@@ -49,6 +50,7 @@
 #include "gtkmenuitem.h"
 #include "gtkmain.h"
 #include "gtksettings.h"
+#include "gtkstylecontextprivate.h"
 
 #include <glib/gprintf.h>
 
@@ -1096,7 +1098,9 @@ add_pid_to_process_list_store (GtkMountOperation              *mount_operation,
   if (pixbuf == NULL)
     {
       GtkIconTheme *theme;
-      theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (mount_operation->priv->dialog)));
+      theme = gtk_css_icon_theme_value_get_icon_theme
+        (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (mount_operation->priv->dialog)),
+                                           GTK_CSS_PROPERTY_ICON_THEME));
       pixbuf = gtk_icon_theme_load_icon (theme,
                                          "application-x-executable",
                                          24,
index 84810e40b9257a00b92802699999a26ca3c39e2f..5d6172dba6f556b8630df1881aa965b79939c0d0 100644 (file)
@@ -38,6 +38,7 @@
 #include "gtkcheckmenuitem.h"
 #include "gtkclipboard.h"
 #include "gtkcomboboxtext.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkdragsource.h"
 #include "gtkentry.h"
 #include "gtkeventbox.h"
@@ -54,6 +55,7 @@
 #include "gtkseparatormenuitem.h"
 #include "gtksizegroup.h"
 #include "gtksizerequest.h"
+#include "gtkstylecontextprivate.h"
 #include "gtktreemodelsort.h"
 #include "gtktreemodelfilter.h"
 #include "gtktreeselection.h"
@@ -1340,10 +1342,9 @@ chooser_set_sort_type (GtkRecentChooserDefault *impl,
 static GtkIconTheme *
 get_icon_theme_for_widget (GtkWidget *widget)
 {
-  if (gtk_widget_has_screen (widget))
-    return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
-
-  return gtk_icon_theme_get_default ();
+  return gtk_css_icon_theme_value_get_icon_theme
+    (_gtk_style_context_peek_property (gtk_widget_get_style_context (widget),
+                                       GTK_CSS_PROPERTY_ICON_THEME));
 }
 
 static gint
index 2a28742c0dab737b200c1361c4f7693fe1743870..39e09da02684d0d4b78366f89edd94a19a2a24bc 100644 (file)
@@ -36,6 +36,7 @@
 #include "gtkaccelgroupprivate.h"
 #include "gtkbindings.h"
 #include "gtkcsscornervalueprivate.h"
+#include "gtkcssiconthemevalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
 #include "gtkcssshadowsvalueprivate.h"
 #include "gtkkeyhash.h"
@@ -4412,7 +4413,9 @@ icon_list_from_theme (GtkWindow   *window,
   gint *sizes;
   gint i;
 
-  icon_theme = gtk_icon_theme_get_for_screen (_gtk_window_get_screen (window));
+  icon_theme = gtk_css_icon_theme_value_get_icon_theme
+    (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (window)),
+                                       GTK_CSS_PROPERTY_ICON_THEME));
 
   sizes = gtk_icon_theme_get_icon_sizes (icon_theme, name);
 
@@ -4514,7 +4517,9 @@ gtk_window_realize_icon (GtkWindow *window)
 
       g_list_free_full (icon_list, g_object_unref);
  
-      icon_theme = gtk_icon_theme_get_for_screen (_gtk_window_get_screen (window));
+      icon_theme = gtk_css_icon_theme_value_get_icon_theme
+        (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (window)),
+                                           GTK_CSS_PROPERTY_ICON_THEME));
       g_signal_connect (icon_theme, "changed",
                        G_CALLBACK (update_themed_icon), window);
     }
@@ -4601,7 +4606,9 @@ gtk_window_unrealize_icon (GtkWindow *window)
     {
       GtkIconTheme *icon_theme;
 
-      icon_theme = gtk_icon_theme_get_for_screen (_gtk_window_get_screen (window));
+      icon_theme = gtk_css_icon_theme_value_get_icon_theme
+        (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (window)),
+                                           GTK_CSS_PROPERTY_ICON_THEME));
 
       g_signal_handlers_disconnect_by_func (icon_theme, update_themed_icon, window);
     }